//
//  SIAutoReportInfo.m
//  BlueToothSDK
//
//  Created by Piccolo on 2017/11/17.
//  Copyright © 2017年 Piccolo. All rights reserved.
//

#import "SIAutoReportInfo.h"

@implementation SIAutoReportInfo

- (instancetype)initWithSmartITCampingLightAutoReportInfoData:(NSData *)infoData {
    if (!self) {
        self = [self init];
    }
    /* <10 0fd2 58 00 00 01 00 01 142400 00000017 231affff>, */
    if (self) {
        Byte *infoDataBytes = (Byte *)infoData.bytes;
        //电池电压 2bit (1, 2)
        _lightVoltage = (infoDataBytes[1] << 8) + infoDataBytes[2];
        //电池电量 1bit (3)
        _lightBattery = infoDataBytes[3];
        //电池状态 1bit (4)
        _lightBatteryStatus = infoDataBytes[4];
        //SOS状态, 声控状态, 指示灯状态 1bit (5)
        NSString *enablingBinaryString = [SIUtil decimalToBinary:(int)infoDataBytes[5] backLength:8];
        NSInteger sosStatus = [SIUtil stringOfEndIndex:0 totalString:enablingBinaryString].integerValue;
        NSInteger soundStatus = [SIUtil stringOfEndIndex:1 totalString:enablingBinaryString].integerValue;
        NSInteger indicatorStatus = [SIUtil stringOfEndIndex:2 totalString:enablingBinaryString].integerValue;
        NSInteger awakenStatus = [SIUtil stringOfEndIndex:3 totalString:enablingBinaryString].integerValue;
        //工作模式 1bit (6)
        NSSILightMode mode = infoDataBytes[6];
        //亮度 1bit (7)
        NSUInteger brightnessValue = infoDataBytes[7];
        //色温 1bit (8)
        NSUInteger colorTempValue = infoDataBytes[8];
        //Smart 时分秒 (9-11)
        NSUInteger smartTimeHour = infoDataBytes[9];
        NSUInteger smartTimeMinute = infoDataBytes[10];
        NSUInteger smartTimeSecond = infoDataBytes[11];
       
        //new v1.21
        //唤醒开启时间 2bit (11, 12)
        NSUInteger awakenOnTimeHour = infoDataBytes[12];
        NSUInteger awakenOnTimeMinute = infoDataBytes[13];
        //定时结束时间 2bit (13, 14)
        NSUInteger awakenOffTimeHour = infoDataBytes[14];
        NSUInteger awakenOffTimeMinute = infoDataBytes[15];
        
        //系统时间
        NSUInteger systemTimeHour = infoDataBytes[16];
        NSUInteger systemTimeMinute = infoDataBytes[17];
        NSUInteger systemTimeSecond = infoDataBytes[18];
        
        SILightTimeInfo *lightTimeInfo = [[SILightTimeInfo alloc] initWithSmartTimeHour:(NSUInteger)smartTimeHour
                                                                        smartTimeMinute:(NSUInteger)smartTimeMinute
                                                                        smartTimeSecond:(NSUInteger)smartTimeSecond
                                                                       awakenOntimeHour:awakenOnTimeHour
                                                                     awakenOnTimeMinute:awakenOnTimeMinute
                                                                      awakenOffTimeHour:awakenOffTimeHour
                                                                    awakenOffTimeMinute:awakenOffTimeMinute
                                                                         systemTimeHour:systemTimeHour
                                                                       systemTimeMinute:systemTimeMinute
                                                                       systemTimeSecond:systemTimeSecond];
        
        SILightAddtionalInfo *lightAddtionalInfo = [[SILightAddtionalInfo alloc] initWithSosStatus:sosStatus
                                                              indicatorStatus:indicatorStatus
                                                                  soundStatus:soundStatus
                                                                 awakenStatus:awakenStatus];
        
        
        _lightInfo = [[SILightInfo alloc] initWithLightMode:mode
                                            brightnessValue:brightnessValue
                                             colorTempValue:colorTempValue
                                              lightTimeInfo:lightTimeInfo
                                         lightAddtionalInfo:lightAddtionalInfo];
    }
    return self;
}
@end
